package com.corner.ui.adapter;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.amap.api.services.core.PoiItem;
import com.corner.R;
import com.corner.utils.view.FindView;
import com.corner.utils.view.InjectViewUtils;

import java.util.List;

/**
 * Created by Administrator on 2015/7/23，22.56.
 * 描述：
 */
public class SelectLocationAdapter extends BaseAdapter {
    private List<PoiItem> items;
    private Context context;

    public SelectLocationAdapter(List<PoiItem> items, Context context) {
        this.items = items;
        this.context = context;
    }

    @Override
    public int getCount() {
        return items.size();
    }

    @Override
    public Object getItem(int position) {
        return items.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        if (convertView == null) {
            convertView = View.inflate(context, R.layout.lv_select_location_item, null);
            Holder holder = new Holder();
            InjectViewUtils.injectView(holder, convertView, context);
            convertView.setTag(holder);
        }
        Holder holder = (Holder) convertView.getTag();
        holder.tvAddr.setText(items.get(position).getSnippet());
        holder.tvName.setText(items.get(position).getTitle());
        return convertView;
    }

    public void changeList(List<PoiItem> poiItems) {
        this.items = poiItems;
        notifyDataSetChanged();
    }

    public class Holder {
        @FindView(R.id.tv_select_location_item_name)
        TextView tvName;
        @FindView(R.id.tv_select_location_item_address)
        TextView tvAddr;
    }
}
